package com.cskaoyan.shopping.service.impl;

import com.cskaoyan.mall.dto.ClearCartItemRequest;
import com.cskaoyan.shopping.dto.CartProductDto;
import com.cskaoyan.shopping.service.ICartOrderService;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Map;

/**
 * @ProjectName duolaimall
 * @Descriptiom TODO
 * @Aurhor: 蔡文强
 * @Since: 2022/10/26 17:06
 */
@Service
public class ICartOrderServiceImpl implements ICartOrderService {

    @Autowired
    RedissonClient redissonClient;

    @Override
    public void clearCartItemByUserID(ClearCartItemRequest request) {

        @NotNull Long userId = request.getUserId();
        @NotEmpty List<Long> productIds = request.getProductIds();

        Map<String, CartProductDto> cartMap = redissonClient.getMap("tb_cart" + userId);
        for (Long productId : productIds) {
            cartMap.remove(productId.toString());
        }
    }
}
